import pandas as pd

df = pd.read_csv("preprocessed2.csv")


def rating_to_weight(rating, r_min=2.0, r_max=10.0, alpha=2.0):
    normed = (rating - r_min) / (r_max - r_min)
    return 1 + 3 * (normed**alpha)


genre_cols = [
    "joy_and_escapism",
    "Stimulation_and_Adventure",
    "Realism_and_Depth",
    "Anxiety_Conflict",
    "Documentary_and_Public",
    "Other",
]

# 对每一列加权
for col in genre_cols:
    df[col] = df.apply(
        lambda row: (
            row[col] * rating_to_weight(row["average_rating"]) if row[col] > 0 else 0
        ),
        axis=1,
    )

df.to_csv("加权后的分组得分.csv", index=False)
